#include <iostream>
#include <math.h>
#include <set>
using std::set;
using std::cout;
using std::endl;
template <typename T>
void display(T t){
    for(auto i : t){
        cout << i << endl;
    }
}


class Point{
public:
    Point(float x,float y)
        :_x(x),_y(y)
    {
    }

    float getdistance() const{
        return hypot(_x,_y);
    }
    //friend bool operator<(const Point& lhs,const Point& rhs);
    friend std::ostream& operator<<(std::ostream& os,Point & pt);
    friend class compare_set;
    friend std::less<Point>;
private:
    float _x;
    float _y;
};
#if 0
bool operator<(const Point& lhs,const Point& rhs){
    if(lhs.getdistance() < rhs.getdistance()){
        return true;
    }
    if(lhs.getdistance() == rhs.getdistance()){
        if(lhs._x < rhs._x){
            return true;
        }
        if(lhs._x == rhs._x && lhs._y < rhs._y){
            return true;
        }
    }
    return false;
}
#endif
std::ostream& operator<<(std::ostream& os,Point & pt){
    os <<"(" <<pt._x << "," << pt._y <<")";
    return os;
}

struct compare_set{
    bool operator()(const Point& lhs,const Point& rhs) const{
        if(lhs.getdistance() < rhs.getdistance()){
            return true;
        }
        if(lhs.getdistance() == rhs.getdistance()){
            if(lhs._x < rhs._x){
                return true;
            }
            if(lhs._x == rhs._x && lhs._y < rhs._y){
                return true;
            }
        }
        return false;
    }
};


void test(){
    set<Point,compare_set> s1;
    s1.emplace(1,2);
    s1.emplace(2,3);
    s1.emplace(3,3);
    s1.emplace(2,3);
    s1.emplace(6,3);
    s1.emplace(8,3);
    s1.emplace(2,5);
    display(s1);
}

int main()
{


    test ();
    return 0;
}

